package com.geovis.emergency.spd.biz.basic.wrapper;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.geovis.emergency.spd.biz.basic.service.IBasicLabelService;
import com.geovis.emergency.spd.biz.pc.wrapper.BaseEntityWrapper;
import com.geovis.emergency.spd.entity.basic.entity.BasicLabel;
import com.geovis.emergency.spd.entity.basic.entity.BasicLabelGroup;
import com.geovis.emergency.spd.entity.basic.pojo.vo.BasicLabelGroupVO;
import com.geovis.emergency.spd.entity.pc.pojo.enums.StatusEnum;
import lombok.AllArgsConstructor;

/**
 * @author Lonsho
 * @version 1.0
 * @date 2022/3/16
 */
@AllArgsConstructor
public class BasicLabelGroupWrapper extends BaseEntityWrapper<BasicLabelGroup, BasicLabelGroupVO> {
    private final IBasicLabelService cfgLabelService;

    public static BasicLabelGroupWrapper build(IBasicLabelService cfgLabelService){
        return new BasicLabelGroupWrapper(cfgLabelService);
    }
    @Override
    public BasicLabelGroupVO entityVO(BasicLabelGroup entity) {
        BasicLabelGroupVO cfgLabelGroupVO = new BasicLabelGroupVO();
        BeanUtil.copyProperties(entity,cfgLabelGroupVO);
        LambdaQueryWrapper<BasicLabel> wrapper = Wrappers.lambdaQuery();
        if (ObjectUtil.isNotNull(entity.getId())){
            wrapper.eq(BasicLabel::getGroupId,entity.getId());
        }
        cfgLabelGroupVO.setLabelCount(cfgLabelService.count(wrapper));
        return cfgLabelGroupVO;
    }
}
